package com.aipodcast.webbackend.controller;

import com.aipodcast.webbackend.config.model.ApiResponse;
import com.aipodcast.webbackend.entity.req.LoginReq;
import com.aipodcast.webbackend.entity.req.RegisterReq;
import com.aipodcast.webbackend.entity.vo.UserVo;
import com.aipodcast.webbackend.service.IUsersService;
import com.aipodcast.webbackend.utils.ApiResponseUtils;
import com.aipodcast.webbackend.utils.IpUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2025-09-22
 */
@RestController
@RequestMapping("/users")
public class UsersController {

    @Resource
    private IUsersService usersService;

    @PostMapping("/register")
    public ApiResponse<String> register(HttpServletRequest request, @RequestBody RegisterReq registerReq) {
        usersService.register(IpUtil.getIp(request), registerReq);
        return ApiResponseUtils.success("注册成功");
    }

    @PostMapping("/login")
    public ApiResponse<String> login(HttpServletRequest request, @RequestBody LoginReq loginReq) {
        String token = usersService.login(IpUtil.getIp(request), loginReq);
        return ApiResponseUtils.success(token);
    }
}
